
package com.beiru.oss;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.WritableMap;

public class RNOssModule extends ReactContextBaseJavaModule {

  private final ReactApplicationContext reactContext;

  public RNOssModule(ReactApplicationContext reactContext) {
    super(reactContext);
    this.reactContext = reactContext;
  }

  @Override
  public String getName() {
    return "RNOss";
  }

   @ReactMethod
      public void uploadFileArr(ReadableArray arr,final Promise promise){
          //Log.d(TAG, "uploadFileArr: ");
          if(arr==null || arr.size()==0){
              promise.reject("-1","传入上传列表为空");
              return;
          }
          OSSManager.getInstance(getReactApplicationContext()).uploadFileArr(arr, new OSSManager.OSSCallback() {
              @Override
              public void onResult(WritableMap map) {
                  if(map == null){
                      promise.reject("-2","有文件上传失败");
                  }else{

                      promise.resolve(map);
                  }
              }
          });
      }
     @ReactMethod
       public void configWithHost(String host){
           OSSManager.getInstance(getReactApplicationContext()).host=host;
           OSSManager.getInstance(getReactApplicationContext()).config();
       }
}
